#!/bin/bash
backup_dir=$ORACLE_BASE/backup
log_file=$ORACLE_BASE/admin/$ORACLE_SID/hot_backup_$ORACLE_SID.log
echo "Beginning hot backup..." > $log_file
date >> $log_file

sqlplus -s / as sysdba << EOF >> $log_file
alter database backup controlfile to '/$backup_dir/backup_controlfile.ctl';
set pagesize 0
set linesize 1000
set feedback off
column tablespace_name noprin
column sortorder noprin
column textout format a210

spool hot_backup_$ORACLE_SID.sql

select tablespace_name,'1' sortorder,
       'alter tablespace ' || tablespace_name || ' begin backup;' textout from dba_data_files
union
select tablespace_name,'2' sortorder,
       'host cp ' || file_name || ' ' || '$backup_dir' textout
from dba_data_files
union
select tablespace_name,'3' sortorder,
       'alter tablespace ' || tablespace_name || ' end backup;' textout
from dba_data_files
order by tablespace_name,sortorder,textout;

select 'alter system archive log current;' from dual;
spool off

@hot_backup_$ORACLE_SID.sql
exit
EOF

rm -f hot_backup_$ORACLE_SID.sql
echo "Hot backup finished." >> $log_file
